const app = getApp();
const http = require('../../../utils/http.js')

Component({
  options: {
    addGlobalClass: true,
  },
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    TabCur: 'NORMAL',
    SortMenu: [{id: 'NORMAL', name: "优惠券"}, {id: 'merNORMAL', name: "团购券"}],
    time: 0,
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    lines: 0,
    swiperList: [],
    gridList:[],
    couponList:[],
    merchantList:[],
    xsqgItem:{},
    xsmsItem:{}
  },

  /**
   * 组件的方法列表
   */
  methods: {
    search() {
      // wx.navigateTo({
      //   url: '/pages/home/search/search'
      // });
    },
    tabSelect(e) {
      this.setData({
        TabCur: e.currentTarget.dataset.id
      })
      let postData = {stockType: e.currentTarget.dataset.id}
      this.selectCouponList(postData)
    },
    selectCouponList(data) {
      //查询优惠券列表
      http.get('/api/index/selectCouponList', data).then(res => {
        if (res.code == 200) {
          this.setData({
            couponList: res.result
          })
        }
      })
    }
  },

  lifetimes: {
    attached: function() {
      wx.login({
        success: res => {
          //轮播和九宫格
          http.get('/api/index/selectSwiperAndGrids').then(res => {
            if (res.code == 200) {
              this.setData({
                swiperList: res.result.swipers,
                gridList: res.result.grids
              })
            }
          })
          //查询限时
          http.get('/api/index/selectActivity', {type: 3}).then(res => {
            if (res.code == 200) {
              this.setData({
                xsqgItem: res.result
              })
            }
          })
          //限时秒杀
          http.get('/api/index/selectActivity',{type: 4}).then(res => {
            if (res.code == 200) {
              this.setData({
                xsmsItem: res.result
              })
            }
          })
          //查询品牌
          http.get('/api/index/selectMerchant').then(res => {
            if (res.code == 200) {
              this.setData({
                merchantList: res.result.slice(0,9)
              })
            }
          })

          //this.selectCouponList({stockType: 'NORMAL'})

        }
      })
    }
  },
})
